/**
 * @module ISprite 
 * 1. 保存当前精灵的所有渲染状态，继承自IRenderState
 * 2. 持有一个数学变换系统，继承处ITransformable接口，用以表示平移、旋转及缩放等操作
 * 3. 点选碰撞检测操作
 * 4. 响应鼠标、键盘、更新及渲染事件
 */
import ITransformable from "./ITransformable";
import IRenderState from "./IRenderState";
import IShape from "./IShape";
import ISpriteContainer from "./ISpriteContainer";
import Vector2 from "../maths/Vector2";
import EOrder from "../enums/EOrder";
import CanvasMouseEvent from "../events/CanvasMouseEvent";
import CanvasKeyBoardEvent from "../events/CanvasKeyBoardEvent";

export type UpdateEventHandler = ((spr: ISprite, mesc: number, diffSec: number, travelOrder: EOrder) => void);
export type MouseEventHandler = ((spr: ISprite, evt: CanvasMouseEvent) => void);
export type KeyboardEventHandler = ((spr: ISprite, evt: CanvasKeyBoardEvent) => void);
export type RenderEventHandler = (spr: ISprite, context: CanvasRenderingContext2D, renderOreder: EOrder) => void;

export default interface ISprite extends ITransformable, IRenderState {
    // 当前精灵的名称
    name: string;
    // ISprite引用一个IShape接口，如draw和hitTest都调用IShape对应的同名方法
    shape: IShape;
    // 双向关联，通过owner找到容器对象
    owner: ISpriteContainer;
    // 为了方便起见，有时需要添加一些不知道数据类型的额外数据
    data: any;

    // 点选碰撞检测
    hitTest(localPt: Vector2): boolean;
    // 更新
    update(mesc: number, diff: number, order: EOrder): void;
    // 绘制
    draw(context: CanvasRenderingContext2D): void;
    // 事件处理
    mouseEvent: MouseEventHandler | null;
    keyEvent: KeyboardEventHandler | null;
    updateEvent: UpdateEventHandler | null;
    renderEvent: RenderEventHandler | null;
}